<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	</head>

	<body>
		<input type="button" name="首页" id="btn1" value="首页" onclick="toIndex()"/>
		<input type="text" id="title"/>
		<div id="div1"></div>
		<input type="button" name="发布" id="btn1" value="发布" onclick="commit()"/>
		<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script> -->
		<script src="../node_modules/wangEditor.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
		<script type="text/javascript">
			var toIndex = function () {
				window.location.href = '/';
			}
			var commit = function () {
			  // console.log(editor.txt.text());
			  var ipt = editor.txt.html()
			  var title = document.querySelector('#title').value
			  console.log(ipt);
			  axios.post('/write', {
				  data: ipt,
				  title: title
				})
				.then(function (response) {
				  if (response.toString() == 'success') {
					  alert('发布成功!');
					  window.location.href = '/';
				  }
				})
				.catch(function (error) {
				  console.log(error);
				});
			}
			const E = window.wangEditor
			const editor = new E('#div1')
			// 或者 const editor = new E(document.getElementById('div1'))
			editor.create()
		</script>
	</body>

</html>
